// 应用入口
import { createApp } from 'vue';
import ElementPlus from 'element-plus';
import 'element-plus/dist/index.css';
import zhCn from 'element-plus/es/locale/lang/zh-cn';
import App from './App.vue';
import router from './router';
import pinia from './store';
import * as ElementPlusIconsVue from '@element-plus/icons-vue';
import { initAppData } from './utils/initData';
import ECharts from 'vue-echarts';
import { use } from 'echarts/core';
import {
  CanvasRenderer
} from 'echarts/renderers';
import {
  BarChart,
  LineChart,
  PieChart
} from 'echarts/charts';
import {
  GridComponent,
  TooltipComponent,
  LegendComponent,
  TitleComponent,
  DataZoomComponent
} from 'echarts/components';

use([
  CanvasRenderer,
  BarChart,
  LineChart,
  PieChart,
  GridComponent,
  TooltipComponent,
  LegendComponent,
  TitleComponent,
  DataZoomComponent
]);

// 清理旧的localStorage数据，现在所有数据从MySQL数据库获取
initAppData();

// 创建 Vue 应用
const app = createApp(App);

// 注册 Element Plus 图标
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component);
}

// 注册 ECharts 组件
app.component('v-chart', ECharts);

// 使用插件
app.use(ElementPlus, {
  locale: zhCn,
  size: 'default'
});
app.use(pinia);
app.use(router);

// 挂载应用
app.mount('#app'); 